#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>

using namespace std;

int driving(vector<int> bessie, vector<int> polices){
    int x = 0;

    for(int i = 0; i < bessie.size() && i < polices.size(); ++i){
        if(polices[i] - bessie[i] > x){
            x = polices[i] - bessie[i];
        }
    }
    
    return x;
}

int main(int argc, char const *argv[])
{
    ifstream ifs("speedlimits.in");
    ofstream ofs("speedlimits.out");

    int N = 0, M = 0;
    int L = 0, V = 0;
    vector<int> bessie, polices;

    ifs>>N>>M;

    for(int i = 0; i < N; i++){
        ifs>>L>>V;
        vector<int> tmp(L, V);

        bessie.insert(bessie.end(), tmp.begin(), tmp.end());
    }

    for(int i = 0; i < M; i++){
        ifs>>L>>V;
        vector<int> tmp(L, V);

        polices.insert(polices.end(), tmp.begin(), tmp.end());
    }

    int max = driving(bessie, polices);
    
    cout << max << endl;
    ofs  << max << endl;

    return 0;
}
